#include "led.h"

void led_fun(char *uled)
{
    uint8_t temp = 0x00;
    static uint8_t temp_old = 0xff;

    for (uint8_t i = 0; i < 8;i++)
        temp |= uled[i] << i;

        if(temp != temp_old)
        {
            GPIOC->ODR &= 0x00ff;
            GPIOC->ODR |= ~(temp << 8);

            GPIOD->BSRR |= 0x01 << 2;
            GPIOD->BRR |= 0x01 << 2;

            temp_old = temp;
        }
}

uint8_t uled[8] = {0,0,0,0,0,0,0,0};
void led_proc(void)
{
    if(R37_pass_flag)
    {
        uint32_t time1 = HAL_GetTick();
        if(time1 >= R37_pass_time + 1000)
        {
            R37_pass_flag = 0;
        }
    }

    if (R38_pass_flag)
    {
        uint32_t time2 = HAL_GetTick();
        if (time2 >= R38_pass_time + 1000)
        {
            R38_pass_flag = 0;
        }
    }
    uled[0] = R37_pass_flag;
    uled[1] = R38_pass_flag;
    if(show_mode ==0)
    {
        uled[2] = 1;
        uled[3] = 0;
        uled[4] = 0;
    }
    else if(show_mode ==1)
    {
        uled[2] = 0;
        uled[3] = 1;
        uled[4] = 0;
    }
    else if(show_mode ==2)
    {
        uled[2] = 0;
        uled[3] = 0;
        uled[4] = 1;
    }
    else;
        
    led_fun(uled);
}
